<?php

/**
 * Well Framework
 * 
 * Contains Front Controller pattern class
 * 
 * @package     Well
 *
 * @author Valerii Lazarevych <valeriy.fremar@gmail.com>
 */

/**
 * Class ApplicationHelper
 * Set up configuration settings
 */
class ApplicationHelper
{
    /**
     *
     * @var type ApplicationHelper
     */
    private static $instance;
    
    /**
     * Constructor
     * 
     * @access private static
     */
    private function __construct() {}
    
    /**
     * Get instance of this singleton
     * 
     * @access static public
     */
    public static function instance()
    {
        if (!self::$instance){            
             self::$instance = new self();
        }
        return self::$instance;
    }
    
    /**          
     * Wrapper for $this->getOptions() calling
     */
    public function init()
    {  
       // Get app configuration options
//       $this->getOptions();                        
              
       // Put Session to registry
       ApplicationRegistry::set('session' , new Session() );
       
       // Put request to registry
       ApplicationRegistry::set('request' , new Request() );               
       
       // Put locale to registry
       ApplicationRegistry::set('locale'  , new UserLocale() );
       
       // Put Layout  to registry
       ApplicationRegistry::set('layout'  , new Layout()  ); 
       
       // Set base file path to app files
       FrontController::instance()->setBasePath(dirname(__FILE__).'/../../application/');
    }
    
    /**
     * Require_once configuration options
     */
    public function getOptions()
    {        
        require_once 'configs.php';
    }
    
    /**
     * Error handler
     * 
     * @param type $expr
     * @param type $message 
     */    
    public function ensure( $expr, $message )
    {
        if (!$expr){            
            throw new ApplicationException( $message );        }
    }
    
}
?>
